<template>
  <div>
    <div class="main">
      <eagle-input
        label="文件名称"
        v-model="form.Name"
        name="Name"
        required
      >
      </eagle-input>

      <eagle-input
        label="签字人"
        v-model="form.ChnName"
        name="ChnName"
        required
      >
      </eagle-input>

      <eagle-file-upload
        @CallBack="_fileUploadCb"
        :attachs="form.Attachs"
        :labelName="'签名文件'"
        :mustInput="true"
      />

      <div class="btn_submit">
        <eagle-button
          block
          type="info"
          @click="submit"
        > 提交 </eagle-button>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  data() {
    return {
      id: this.$route.query.id,
      form: {},
    };
  },

  computed: {
    ...mapGetters(["baseUrl", "CompanyCode", "roles"]),
  },

  created() {
    if (this.$route.query.id != null) {
      (this.id = this.$route.query.id), this.getDetail();
    }

    console.log("id", this.$route.query.id);
  },
  methods: {
    _fileUploadCb(attachs) {
      this.form.Attachs = attachs;
    },
    getDetail() {
      let params = { id: this.id };

      if (this.id == 0) {
        this.$axios
          .get("/SitePromiseRecord/InitEntity", { params: params })
          .then((res) => {
            this.form = res.data;
          });
      } else {
        this.$axios
          .get("/SitePromiseRecord/GetDetail", { params: params })
          .then((res) => {
            this.form = res.data;
          });
      }
    },

    submit() {
      if (!this.form.Name) {
        return this.$toast("请输入文件名称");
      }

      if (!this.form.ChnName) {
        return this.$toast("请输入签字人");
      }

      if (!this.form.Attachs) {
        return this.$toast("请选择签名文件");
      } else {
        if (this.form.Attachs.length == 0) {
          return this.$toast("请选择签名文件");
        }
      }
      let form1 = this.form;
      form1.CompanyCode = this.CompanyCode;
      this.$axios
        .post("/SitePromiseRecord/Edit", form1)
        .then((res) => {
          this.loading = false;
          this.$toast.success("保存成功！");
          setTimeout(() => {
            this.$router.goRefresh(-1);
          }, 300);
        })
        .catch((err) => {
          console.log("err", err);
        });
    },
  },
};
</script>

<style lang="less" >
.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
}

.block {
  width: 120px;
  height: 120px;
  background-color: #fff;
}
</style>
<style lang="less" scoped>
.space-between {
  justify-content: space-between;
}
</style>
